package main

import (
	"fmt"
	"unsafe"
)

//常量用作枚举类型

const (
	Female  = 1
	Male    = 2
	UnKnown = 3
	Other   = "zhang"
)
const (
	CategoryBooks    = iota // 0
	CategoryHealth          // 1
	CategoryClothing        // 2
)

// 在下一行增长，而不是立即取得它的引用。
const (
	Apple, Banana = iota + 1, iota + 2
	Cherimoya, Durian
	Elderberry, Fig
)

type Allergen int

const (
	IgEggs         Allergen = 1 << iota // 1 << 0 which is 00000001
	IgChocolate                         // 1 << 1 which is 00000010
	IgNuts                              // 1 << 2 which is 00000100
	IgStrawberries                      // 1 << 3 which is 00001000
	IgShellfish                         // 1 << 4 which is 00010000
)

func main() {
	/**
	常量是一个简单值的标识符，在程序运行时，不会被修改的量。

	常量中的数据类型只可以是布尔型、数字型（整数型、浮点型和复数）和字符串型。
	*/
	//常量的定义格式
	//const identifier[type] = value
	const name = "superzhang"
	fmt.Println(name)

	//name = "superboy"
	//fmt.Println(name)

	const Length = 10
	const Width = 5
	var area int
	const a, b, c = 1, false, "str"
	area = Length * Width
	fmt.Println(" Length * Width = ", area)
	println(a, b, c)

	//常量枚举
	println(Female, Male, UnKnown)

	//字符串类型在 go 里是个结构, 包含指向底层数组的指针和长度,这两部分每部分都是 8 个字节
	//所以字符串类型大小为 16 个字节。
	println(unsafe.Sizeof(Other))
	//字符传长度
	println(len(Other))

	println(CategoryHealth, CategoryClothing, CategoryBooks)

	println(1 << 0)
}
